<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name=renderer content=webkit>
    <title>企业安全追溯平台</title>
    <link rel="stylesheet" href="../../public/dist/css/layui.css">
    <link rel="stylesheet" href="../../css/twoindex.css">
    <link rel="stylesheet" href="../../public/font/iconfont.css">
    <link rel="icon" href="../../public/favicon.ico">
    <script src="../../js/common/jquery.min.js"></script>
    <script src="../../js/twoindex.js"></script>

</head>

<body class="layui-layout-body">
    <div class="layui-layout layui-layout-admin">
        <div class="layui-header layui-bg-cyan">
            <div class="layui-logo two-in-logo">企业安全追溯平台</div>
            <div class="layui-nav layui-layout-left two-in-title">
                <p>欢迎<label class="realname"></label>用户登陆企业安全追溯平台</p>
            </div>

            <div class="layui-nav layui-layout-right two-in-login">
                <a href="javascript:;" class="exits">
                    <i class="iconfont  icon-tuichu" style="font-size:30px;color:#6F6C6C;"></i>
                </a>
                <a href="javascript:;" class="two-in-message">
                    <i class="iconfont  icon-ios-notifications" style="font-size:30px;color:#6F6C6C"></i>
                    <span class="layui-badge-dot"></span>
                </a>
                <div class="layui-nav-item two-in-data">
                    <a href="javascript:;" id="" class="realname" style="margin-right: 11px;">
                        暂未登录
                    </a>
                    <dl class="layui-nav-child">
                        <dd><a href="">基本资料</a></dd>
                        <dd><a href="">安全设置</a></dd>
                    </dl>
                </div>
            </div>
        </div>
        <!-- 上/头部 -->
        <div class="layui-side layui-bg-cyan two-in-menu" id='menu'>
            <div class="layui-side-scroll">
                <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
                <ul class="layui-nav layui-nav-tree layui-bg-cyan two-in-menu" id="twoinmenu" lay-filter="navtest">
                    <li class="layui-nav-item two-in-menu-one sssss" id='tzsidewards'>
                        <label style="cursor: pointer;">切换供应链模式</label>
                        <i class="iconfont icon-shuangjiantouyou"></i>
                    </li>
                    <!--加 layui-nav-itemed 张开 -->
                    <li class="layui-nav-item" id='nav-item-kong'>&nbsp;</li>

                    <li class="layui-nav-item nav-show nav-show-product">
                        <a class="" href="javascript:;">
                            <span class="iconfont">&#xe605;</span> 生产加工
                        </a>
                        <dl class="layui-nav-child" id='nav-product' >

                        </dl>
                    </li>

                    <li class="layui-nav-item nav-show nav-show-farm">
                        <a class="" href="javascript:;">
                            <span class="iconfont">&#xe631;</span> 养殖企业
                        </a>
                        <dl class="layui-nav-child" id='nav-farm'>
                        </dl>
                    </li>

                    <li class="layui-nav-item nav-show nav-show-plant">
                        <a class="" href="javascript:;">
                            <span class="iconfont">&#xe600;</span> 种植企业
                        </a>
                        <dl class="layui-nav-child" id='nav-plant'>

                        </dl>
                    </li>

                    <li class="layui-nav-item nav-show nav-show-food">
                        <a class="" href="javascript:;">
                            <span class="iconfont">&#xe733;</span> 食品经营单位
                        </a>
                        <dl class="layui-nav-child" id='nav-food'>
                        </dl>
                    </li>

                </ul>

                <div class="two-in-menu-bottom" id='hiddenmenu'>
                    隐藏菜单栏
                </div>
            </div>
        </div>

        <div class="layui-body two-in-con">
            <!-- 内容主体区域 -->
            <div style="padding:10px;" class="two-in-coms">
                <iframe scrolling="auto" src="../../src/vertical/Scommon/Amywork/message.html" frameborder="0" id="contentsss" style="width:100%;height:100%;"></iframe>
            </div>
            <div class="showmenu">
                <i class="layui-icon layui-icon-next"></i>
            </div>
        </div>

    </div>
    <script src="../../public/dist/layui.js"></script>
    <script src="../../js/common/api.js"></script>
    <script>
        var sessions = sessionStorage.getItem("keyssname");
        // sessions=''
        if (sessions == "") {
            window.location.href = "../login.html";
        }
        window.onresize = function() {
            getClientHeight();

        };
        getClientHeight();
        //动态给高
        function getClientHeight() {
            var clientHeight = 0;
            if (document.body.clientHeight && document.documentElement.clientHeight) {
                // console.log(document.body.clientHeight)
                var clientHeight = (document.body.clientHeight < document.documentElement.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
            } else {
                var clientHeight = (document.body.clientHeight > document.documentElement.clientHeight) ? document.body.clientHeight : document.documentElement.clientHeight;
            }
            document.querySelector('.two-in-coms').style.height = clientHeight - 90 + 'px';
            return
        }
        var enterpriseType;
        // 获取用户信息
        getUser();

        function getUser(e) {
            handleAjax('user/getUser', {}, "GET").done(function(resp) {
                // console.log(resp);
                var names = document.querySelectorAll('.realname');
                for (var i = 0; i < names.length; i++) {
                    names[i].innerHTML = resp.realName + "(" + resp.username + ")";
                }
                enterpriseType = resp.enterpriseType;
                this.getElement(enterpriseType);
                return
            }).fail(function(err) {
                // console.log(err);
                var names = document.querySelectorAll('.realname');
                for (var i = 0; i < names.length; i++) {
                    names[i].innerHTML = err.realName + "(" + err.username + ")";
                }
                enterpriseType = err.enterpriseType;
                console.log(enterpriseType);
                this.getElement('2345');
                return
            });
        }

        //动态添加菜单
        var elms = "";

        function getElement(enterpriseType) {

            for (var index = 0; index < menudata.length; index++) {
                var elmsProduct = "";
                var elmsFarm = "";
                var elmsPlant = "";
                var elmsFood = "";
                // 公共模块
                if (menudata[index].type == 1) {
                    var child = "";
                    var meunchid = menudata[index].child;
                    if (meunchid) {
                        for (var i in meunchid) {
                            if (meunchid[i].type == 1) {
                                child +=
                                    '<dl class="layui-nav-child">' +
                                    '<dd><a href="javascript:;" data-options="' + meunchid[i].url + '">' + meunchid[i].title + '</a></dd>' +
                                    '</dl>'
                                    // console.log(meunchid[i].title);
                            }
                            // }
                        }
                    }
                    elms += '<li class="layui-nav-item">' +
                        '<a class="" href="javascript:;">' +
                        '<i class="iconfont ' + menudata[index].icon + '"></i>' + menudata[index].title + '</a >' +
                        child +
                        '</li>'
                }

                // document.querySelector(".two-in-menu ul>li:last-child").setAttribute("lay-unselect", "");
                // 生产加工，养殖企业，种植企业，食品经营模块
                for (var enterpriseTypeIndex = 0; enterpriseTypeIndex < enterpriseType.length; enterpriseTypeIndex++) {
                    // console.log(enterpriseTypeIndex);
                    if (menudata[index].type == enterpriseType[enterpriseTypeIndex]) {
                        // console.log('enterpriseType[enterpriseTypeIndex]:', enterpriseType[enterpriseTypeIndex]);
                        var child = "";
                        var meunchid = menudata[index].child;
                        if (meunchid) {
                            for (var i in meunchid) {
                                // console.log(meunchid[i].title)
                                if (meunchid[i].type == enterpriseType[enterpriseTypeIndex]) {
                                    child +=
                                        '<dl class="layui-nav-child">' +
                                        '<dd><a href="javascript:;" data-options="' + meunchid[i].url + '">' + meunchid[i].title + '</a></dd>' +
                                        '</dl>'
                                }

                            }
                        }
                        if (enterpriseType[enterpriseTypeIndex] == 2) {
                            elmsProduct += '<dd class="layui-nav-item">' +
                                '<a class="" href="javascript:;">' +
                                '<i class="iconfont ' + menudata[index].icon + '"></i>' + menudata[index].title + '</a >' +
                                child +
                                '</dd>'
                            document.querySelector(".nav-show-product").style.display='block';
                            document.querySelector("#nav-product").innerHTML += elmsProduct;
                            document.querySelector(".two-in-menu ul>li:last-child").setAttribute("lay-unselect", "");
                        } else if (enterpriseType[enterpriseTypeIndex] == 3) {
                            elmsFarm += '<dd class="layui-nav-item">' +
                                '<a class="" href="javascript:;">' +
                                '<i class="iconfont ' + menudata[index].icon + '"></i>' + menudata[index].title + '</a >' +
                                child +
                                '</dd>'
                            document.querySelector(".nav-show-farm").style.display='block';
                            document.querySelector("#nav-farm").innerHTML += elmsFarm;
                            
                        } else if (enterpriseType[enterpriseTypeIndex] == 4) {
                            elmsPlant += '<dd class="layui-nav-item">' +
                                '<a class="" href="javascript:;">' +
                                '<i class="iconfont ' + menudata[index].icon + '"></i>' + menudata[index].title + '</a >' +
                                child +
                                '</dd>'
                            document.querySelector(".nav-show-plant").style.display='block';
                            document.querySelector("#nav-plant").innerHTML += elmsPlant;
                        } else if (enterpriseType[enterpriseTypeIndex] == 5) {
                            elmsFood += '<dd class="layui-nav-item">' +
                                '<a class="" href="javascript:;">' +
                                '<i class="iconfont ' + menudata[index].icon + '"></i>' + menudata[index].title + '</a >' +
                                child +
                                '</dd>'
                            document.querySelector(".nav-show-food").style.display='block';
                            document.querySelector("#nav-food").innerHTML += elmsFood;
                        }
                        // elms += '<dd class="layui-nav-item">' +
                        //     '<a class="" href="javascript:;">' +
                        //     '<i class="iconfont ' + menudata[index].icon + '"></i>' + menudata[index].title + '</a >' +
                        //     child +
                        //     '</dd>'
                    }
                }

            }


            // 左侧菜单
            layui.use('element', function() {
                var $ = layui.$,
                    element = layui.element;
                //左侧公共
                // console.log('elms:', elms)
                $("#nav-item-kong").after(elms);
                element.init();
                element.on('nav(navtest)', function(elem) {
                    var cun = elem[0].dataset.options
                    if (cun != undefined) {
                        $("#contentsss").attr("src", cun)
                    }
                });
                element.render('nav');


                /*切换菜单模式*/
                $("#tzsidewards").click(function() {
                    window.location.href = "../../index.html";
                });

                /*退出*/
                $(".exits").click(function() {
                    window.location.href = "../login.html";
                })
            });
        }
    </script>
</body>

</html>
<script>
    document.querySelector('#hiddenmenu').addEventListener('click', function() {
        document.querySelector('.layui-body').classList.add('two-all');
        document.querySelector('.showmenu').style.display = 'flex';
        // document.querySelector('#hiddenmenu').style.backgroundColor = '#fff';
    })
    document.querySelector('.showmenu').addEventListener('click', function() {
        document.querySelector('.layui-body').classList.remove('two-all');
        document.querySelector('.showmenu').style.display = 'none';
        // document.querySelector('#hiddenmenu').style.backgroundColor = '#009688';
    })

    
</script>
